#ifndef FILEIODEVICE_H_INCLUDED
#define FILEIODEVICE_H_INCLUDED

#include <Common/IInputDevice.h>

namespace Common {
	
/** FileInput device implementation 
 *  It uses file mapping for bytes access
 *  Implementation is not thread-safe
 * 
 */
class FileInputDevice : public IInputDevice {
public :
	
	FileInputDevice();
	~FileInputDevice();
	
	/** init class. Opens file an ddefine total file size
	 *  @throw InputDeviceException
	 *  	if error occurred
	 */
	void init(const char *filename) throw (InputDeviceException);
	
	/** @inherited from IInputDevice */
	// @{
	virtual boost::int64_t expectedSize() const;
	virtual std::size_t readBlock(char * buf, boost::int64_t from, boost::int64_t to)  throw (InputDeviceException);
	virtual std::size_t readSome(char * buf, std::size_t bufferSize) { return 0; }
	// @}
	
private:
	boost::int64_t m_fileSize;
	
	/** File descriptor */
	int m_fd;
	
	const long m_pageSize; 
	std::size_t m_mmapFrameSize;
	
	char * m_mappedAddr;
	off_t m_offsetByte;
	size_t m_lengthBytes;
};	

typedef boost::shared_ptr<FileInputDevice> FileInputDevicePtr;

} // namespace common


#endif

